package com.lzxuni.modules.index;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.lzxuni.modules.common.controller.BaseController;
import com.lzxuni.modules.common.entity.FileEntity;
import com.lzxuni.modules.common.entity.PageData;
import com.lzxuni.modules.common.entity.PageParameter;
import com.lzxuni.modules.common.service.FileEntityService;
import com.lzxuni.modules.enterprise.entity.EnterpriseInfo;
import com.lzxuni.modules.enterprise.service.EnterpriseInfoService;
import com.lzxuni.modules.informationpublish.entity.InformationPublishPressRelease;
import com.lzxuni.modules.informationpublish.service.InformationPublishPressReleaseService;
import com.lzxuni.modules.productdisplay.entity.ProductDisplay;
import com.lzxuni.modules.productdisplay.service.ProductDisplayService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.LinkedList;
import java.util.List;

@RestController
public class WelcomeController extends BaseController {

    @Autowired
    private ProductDisplayService productDisplayService;
    @Autowired
    private InformationPublishPressReleaseService informationPublishPressReleaseService;
    @Autowired
    private FileEntityService fileEntityService;
    @Autowired
    private EnterpriseInfoService enterpriseInfoService;

    @RequestMapping("/common/top.html")
    public ModelAndView top(String type) throws Exception {
        ModelAndView mv = new ModelAndView("/common/top");
        if (StringUtils.isEmpty(type)) {
            type = "网站首页" ;
        }
        mv.addObject("type", type);
        return mv;
    }
    @RequestMapping("/common/footer.html")
    public ModelAndView footer() throws Exception {
        ModelAndView mv = new ModelAndView("/common/footer");
        return mv;
    }
    //新闻公告
//    @RequestMapping("/news.html")
    @RequestMapping(value = "/xinwgg/{newsType}",method = RequestMethod.GET)
    public ModelAndView news(@PathVariable String newsType) throws Exception {
        ModelAndView mv = new ModelAndView("/news");
        int count = informationPublishPressReleaseService.count(new QueryWrapper<InformationPublishPressRelease>().ne("news_type", "bgt"));
        mv.addObject("count", count);
        mv.addObject("newsType", newsType);
        return mv;
    }


    //新增企业
    @RequestMapping("/NewEnterprises.html")
    public ModelAndView newenterprises() throws Exception {
        ModelAndView mv = new ModelAndView("/NewEnterprises");
        return mv;
    }
    //曝光台
//    @RequestMapping("/NewExposureStage.html")
    @RequestMapping(value = "/NewExposureStage/{newsType}",method = RequestMethod.GET)
    public ModelAndView newexposureStage(@PathVariable String newsType) throws Exception {
        ModelAndView mv = new ModelAndView("/NewExposureStage");
        int count = informationPublishPressReleaseService.count(new QueryWrapper<InformationPublishPressRelease>().eq("news_type", newsType));
        mv.addObject("count", count);
        mv.addObject("newsType", newsType);
        return mv;
    }

    //曝光台详细页
    @RequestMapping(value = "/NewExposureStage_details/{newsId}",method = RequestMethod.GET)
    public ModelAndView newexposureStagedetails(@PathVariable String newsId) throws Exception {
        ModelAndView mv = new ModelAndView("/NewExposureStage_xx");
        List<InformationPublishPressRelease> bgtList = informationPublishPressReleaseService.list(new QueryWrapper<InformationPublishPressRelease>().eq("news_id",newsId));
        mv.addObject("bgtList", bgtList);
        return mv;
    }
    //曝光台按类型列表页分页
    @RequestMapping("/listDoType.html")
    public Object typelistDo(String pagination,String newsType) throws Exception {
        PageParameter pageParameter = JSON.parseObject(pagination.replaceAll("&＃39;", "\""), PageParameter.class);
        PageInfo<InformationPublishPressRelease> pageInfo = informationPublishPressReleaseService.queryPagebm(pageParameter,newsType);
        List<InformationPublishPressRelease> list = pageInfo.getList();
        for (InformationPublishPressRelease informationPublishPressRelease : list) {
            informationPublishPressRelease.setContent(com.lzxuni.common.utils.StringUtils.removeHtml(informationPublishPressRelease.getContent()));
        }
        PageData pageData = getPageData(pageInfo);
        return pageData;
    }




}
